package archer.application.elastic.mock.point.entity;

import archer.application.elastic.mock.core.entity.user.User;
import archer.application.elastic.mock.point.ArcherApplicationPointModule;
import archer.framework.common.entity.BaseEntity;
import archer.framework.elastic.entity.ElasticSupportEntity;
import com.avaje.ebean.annotation.DocCode;
import com.avaje.ebean.annotation.DocEmbedded;
import com.avaje.ebean.annotation.DocStore;

import javax.persistence.*;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.List;

/**
 * @author suzx
 * @date 2016/7/1
 */
@DocStore
@Entity
public class UserPoint extends BaseEntity {

    public static final Find<UserPoint> find = new Find<UserPoint>(UserPoint.class);
    public static final ElasticSupportEntity.Elastic<UserPoint> elastic = new ElasticSupportEntity.Elastic<UserPoint>(UserPoint.class);

    @Column(columnDefinition = "decimal(24,2) default 0 COMMENT '当前积分'")
    private BigDecimal currentPoint = BigDecimal.ZERO;

    @Column(columnDefinition = "decimal(24,2) default 0  COMMENT '累计获得积分'")
    private BigDecimal acquirePoint = BigDecimal.ZERO;

    @Column(columnDefinition = "decimal(24,2) default 0  COMMENT '累计消费积分'")
    private BigDecimal consumePoint = BigDecimal.ZERO;

    @Column(columnDefinition = "datetime COMMENT '过期时间'")
    private Timestamp expirationTime = ArcherApplicationPointModule.defaultExpireTime;

    @Column(columnDefinition = "varchar(20) default 'literal character' COMMENT '分析的字段'")
    private String analyzed;

    @DocCode
    @Column(columnDefinition = "varchar(20) default 'literal character' COMMENT '不分析的字段'")
    private String notAnalyzed;

    @DocEmbedded(doc = "id")
    @OneToOne
    @JoinColumn(name = "user_id")
    private User user;

    @DocEmbedded
    @OneToMany(mappedBy = "userPoint")
    private List<PointDetail> pointDetails;

    public BigDecimal getCurrentPoint() {
        return currentPoint;
    }

    public UserPoint setCurrentPoint(BigDecimal currentPoint) {
        this.currentPoint = currentPoint;
        return this;
    }

    public BigDecimal getAcquirePoint() {
        return acquirePoint;
    }

    public UserPoint setAcquirePoint(BigDecimal acquirePoint) {
        this.acquirePoint = acquirePoint;
        return this;
    }

    public BigDecimal getConsumePoint() {
        return consumePoint;
    }

    public UserPoint setConsumePoint(BigDecimal consumePoint) {
        this.consumePoint = consumePoint;
        return this;
    }

    public Timestamp getExpirationTime() {
        return expirationTime;
    }

    public UserPoint setExpirationTime(Timestamp expirationTime) {
        this.expirationTime = expirationTime;
        return this;
    }

    public User getUser() {
        return user;
    }

    public UserPoint setUser(User user) {
        this.user = user;
        return this;
    }

    public List<PointDetail> getPointDetails() {
        return pointDetails;
    }

    public UserPoint setPointDetails(List<PointDetail> pointDetails) {
        this.pointDetails = pointDetails;
        return this;
    }

    public String getUserId() {
        if (this.user == null) {
            this.user = new User();
        }
        return this.user.getId();
    }

    public UserPoint setUserId(String userId) {
        if (this.user == null) {
            this.user = new User();
        }
        this.user.setId(userId);
        return this;
    }

    public String getAnalyzed() {
        return analyzed;
    }

    public UserPoint setAnalyzed(String analyzed) {
        this.analyzed = analyzed;
        return this;
    }

    public String getNotAnalyzed() {
        return notAnalyzed;
    }

    public UserPoint setNotAnalyzed(String notAnalyzed) {
        this.notAnalyzed = notAnalyzed;
        return this;
    }
}
